<?php 
include("includes/code_admin.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title><?php echo SITEURL; ?> Administrator</title>
<link href="style_admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="script.js"></script>

</head>

<body>
<div id="container">
<table class="main" cellspacing="0" cellpadding="0">
  <tr>
    <td class="header">
    <!-- header start -->
    <?php include("includes/header.php");?>
    <!-- header finish -->
    </td>
  </tr>
  <tr>
    <td class="middle">&nbsp;</td>
  </tr>
  <tr>
    <td>
    <!-- tepa start -->
<?php include("includes/tepa.php"); ?>
    <!-- tepa finish -->
    </td>
  </tr>
  <tr>
    <td>
    <!-- contant start -->
<table class="content" cellspacing="0" cellpadding="0">
  <tr valign="top">
    <td>
    <!-- right col -->
<div class="right_col">
<h3 class="title">Yangi Katalog kiritish</h4>

<div class="add_cat">
<img src="img/folder.png" alt="katalog" align="absmiddle" /> <a href="catalog_add.php">Yangi Katalog kiritish</a></div>
<?php 
if(isset($_POST['send']))
{
	$parent = $_POST['cat'];
	$title = addslashes($_POST['title']);
	if(trim($title) == '')
    {
	$error = "DIQQAT !!! Kataolg nomini yozing";
    }
	else
	{
		$result = mysql_query("INSERT INTO menu (title, parent) VALUES('$title', '$parent')");
		 if($result=='true') 
		 { 
		 echo "<p><b>Yangi Katalog qo'shildi <a href = 'catalog.php'>Katalog sahifasiga</a> </b> </p>";
		 }
		 else 
		 { 
		 echo "<p><b>Afsuski Katalog qo'shilmadi, xatolik</b></p>"; 
		 }
	}
}
if(!isset($_POST['send']) || $error != '')
{
echo "<p style='color:#FF0000'><b> $error </b></p>";
?>

<fieldset style="margin:20px; border:3px solid #D9DCDF; width:60%">
<legend style="color:#728D9E">Yangi Katalog kiritish</legend>

<form name="myform" action="" method="post">
<table width="500" border="0" cellspacing="7" cellpadding="0">
  <tr>
    <td>
 Qaysi ketalog ichida: <br />
<select name="cat">
<option value="0"> -  Asosiy kategoriya - </option>
<? 
$q = mysql_query("SELECT * FROM menu ORDER by sort DESC");
   while ( $r = mysql_fetch_assoc($q) ) {
   $m_a[$r['id']] = array('title' => $r['title'], 'parent' => $r['parent']);
   }

function menu($parent) {
   global $m_a;
   $h_c = false;
   foreach ($m_a as $k => $v ) {
   if ( $v['parent'] == $parent ) {
   if ( $h_c === false ) {
   $h_c = true;
   }
 
   if($v['parent']!= '0') { $belgi =  " -- "; }
   echo '<option value='.$k.'>'.$belgi.$v['title'].'</option>';
   menu($k);

   }
   }
}
menu(0);
?>
</select>
<br /><br />

Katalog nomi:<br />
<input type="text" name="title" size="30" maxlength="25" /></td>
  </tr>
  <tr>
    <td><input type="submit" name="send" value=" Saqlash " /></td>
  </tr>
</table>
</form>
</fieldset>
<?php 
}
?>
</div>
</div>
	<!-- right col finish -->
    </td>
  </tr>
</table>


    <!-- contant finish -->
    </td>
  </tr>
</table>
<!-- futer start -->
<?php include("includes/futer.php"); ?>
<!-- futer finish -->
</div>
</body>
</html>
